<template>
  <div class="box">
    <el-card class="box-card">
      <h1>系统管理</h1>
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="70px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="username">
          <el-input
            v-model="ruleForm.username"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input
            type="password"
            v-model="ruleForm.pass"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <div>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >登录</el-button
          >
          <el-button @click="resetForm('ruleForm')">重新填写</el-button>
        </div>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      ruleForm: {
        username: "Admian",
        pass: "123456",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        pass: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          if (
            this.ruleForm.username == "Admian" &&
            this.ruleForm.pass == "123456"
          ) {
            // 存储token开始时间
            window.localStorage.setItem("tokenStartTime", new Date().getTime());
            window.localStorage.setItem("token", '11111111');
            this.$message({
              type: "success",
              message: "登陆成功",
            });
            this.$router.push("/");
          } else {
            this.$message({
              type: "error",
              message: "登陆失败",
            });
          }
        } else {
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.ruleForm.resetFields();
    },
  },
};
</script>

<style lang="less" scoped>
.box-card {
  // 第四种方法 子元素要设置display: inline-block
  display: inline-block;
  width: 500px;
  height: 320px;
  // opacity: .5;
  // 透明度
  background-color: rgba(66, 129, 165, 0.1);
  background-clip: padding-box;
  color: rgb(211, 202, 202);
  border: 5px solid rgba(150, 204, 235, 0.6);
  margin-bottom: 120px;
  // 水平垂直居中 第一种方法 margin
  // position: absolute;
  // top: 0;
  // left: 0;
  // right: 0;
  // bottom: 0;
  // margin: auto;
  // 水平垂直居中 第二种方法 动画
  // position: absolute;
  // top: 50%;
  // left: 50%;
  // transform: translate(-50%, -50%);
  .el-form {
    padding: 20px 40px;
  }
}
.box {
  // 第四种方法 要有宽高
  width: 100vw;
  height: 100vh;
  background: url("../assets/images/bgc.jpg") no-repeat;
  background-size: 100% 100%;
  // 水平垂直居中 第三种方法  flex
  // display: flex;
  // justify-content: center;
  // align-items: center;
  // 水平垂直居中 第四种方法  display: table-cell
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}
</style>
